home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 June: Reference Library / Dev.CD Jun 96 RL / Dev.CD Jun 96 RL.toast / What's New? / Development Kits / Speech Recognition Mgr 1.5 / SR Sample Code / IM SR Example / MyProcessRecognitionResult.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-18  |  2.2 KB  |  84 lines  |  [TEXT/CWIE]

  1. #include <SpeechRecognition.h>
  2. #include <stdio.h>
  3.  
  4. void MyProcessRecognitionResult (SRRecognitionResult recResult);
  5.  
  6. extern OSErr MyCallPersonInPath (SRPath recognizedPath);
  7.  
  8. #define            kTopLMRefCon         'top '
  9. #define            kCallPersonRefCon    'call'
  10. #define            kRejectedWordRefCon    'rejc'
  11.  
  12. void MyProcessRecognitionResult (SRRecognitionResult recResult)
  13. {
  14.     OSErr                myErr = noErr;
  15.  
  16.     if (recResult) {
  17.         SRLanguageModel    myResultLM;
  18.         Size            myLen;
  19.         
  20.         myLen = sizeof (myResultLM);
  21.         myErr = SRGetProperty (recResult, kSRLanguageModelFormat, &myResultLM, &myLen);
  22.         
  23.         if (!myErr)    {
  24.             long                 myRefCon;
  25.             SRLanguageObject    mySubElement;
  26.             
  27.             myLen = sizeof (myRefCon);
  28.             myErr = SRGetProperty (myResultLM, kSRRefCon, &myRefCon, &myLen);
  29.             
  30.             if (!myErr) {
  31.                 switch (myRefCon) {
  32.                     case kRejectedWordRefCon:
  33.                         /* Here we do nothing if the utterace was rejected */
  34.                         break;
  35.                     
  36.                     case kTopLMRefCon:
  37.                         /*    if it's a valid result from our top-level LM,     */
  38.                         /*    then parse and process its elements             */
  39.                         
  40.                         /* TopLM one sub-element, one of the following:        */
  41.                         /* "<call><person>" (SRPath with kCallPersonRefCon),*/
  42.                         /* "schedule meeting with <person>" (SRPath), or    */
  43.                         /* "view today's schedule" (SRPhrase)                 */
  44.                         
  45.                         /* we get the sub-element                            */
  46.                         myErr = SRGetIndexedItem (myResultLM, &mySubElement, 0);
  47.                         if (!myErr) {
  48.                             myLen = sizeof (myRefCon);
  49.                             myErr = SRGetProperty (mySubElement, kSRRefCon, &myRefCon, &myLen);
  50.                             
  51.                             /* Call a subroutine to process the subelement    */
  52.                             if (!myErr) switch (myRefCon)
  53.                                 {
  54.                                 case kCallPersonRefCon:
  55.                                     myErr = MyCallPersonInPath 
  56.                                                         ((SRPath) mySubElement);
  57.                                     break;
  58.                                 
  59.                                 /* process "schedule meeting with <person>"    */
  60.                                 
  61.                                 /* process "view today's schedule"             */
  62.                                 
  63.                                 default:
  64.                                     break;
  65.                                 }
  66.                             
  67.                             /* release subelement when done with it         */
  68.                             myErr = SRReleaseObject (mySubElement);
  69.                         }
  70.                         break;
  71.                 }
  72.             }
  73.             
  74.             /*    release myResultLM fetched above when done with it             */
  75.             myErr = SRReleaseObject (myResultLM);
  76.         }
  77.         
  78.         /* Release SRRecognitionResult since we are done with it             */
  79.         myErr = SRReleaseObject (recResult);
  80.     }
  81.     
  82. }
  83.  
  84.